package cn.x.kindergarten.controller;

import java.io.Serializable;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.x.kindergarten.domain.Child;
import cn.x.kindergarten.service.ChildService;
import cn.x.kindergarten.util.Tools;

@Controller
@RequestMapping("/child")
public class ChildController {
	@Resource(name="childService")
	public ChildService childService;
	
	@RequestMapping("/addUI.action")
	public String addChildUI(){
		return "addChildUI";
	}
	
	@RequestMapping("addChild.action")
	public String addChild(Child child){
		child.setId(Tools.genID());
		this.childService.insert(child);
		return "redirect:/main/index.action";
	}
	
	@RequestMapping("/deleteChild.action")
	public String deleteChild(String id){
		this.childService.delete(id);
		return "redirect:/main/index.action";
	}
	
	@RequestMapping("updateChildUI.action")
	public String updateChildUI(String id, Model model){
		Child child = this.childService.query(id);
		model.addAttribute("child", child);
		return "updateChildUI";
	}
	
	@RequestMapping("updateChild.action")
	public String updateChild(Child child){
		this.childService.update(child);
		return "redirect:/main/index.action";
	}
}
